<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta
            name="viewport"
            content="initial-scale=1.0, user-scalable=no, width=device-width"
    />
    <title>HELLO，AMAP!</title>
    <style>
        html,
        body,
        #container {
          width: 100%;
          height: 100%;
        }
    </style>
</head>
<body>
<div id="container"></div>
</body>
</html>
<script type="text/javascript">
    window._AMapSecurityConfig = {
      securityJsCode: "d51ec3eb3baeaab857d77e1d1cf7d0d6",
    };
</script>
<script
        type="text/javascript"
        src="https://webapi.amap.com/maps?v=2.0&key=f1e7a35b4004dcc18b318ae4c7385b9c"
></script>
<script type="text/javascript">
    var zoom = 16

    //地图初始化应该在地图容器 <div> 已经添加到 DOM 树之后
    var map = new AMap.Map("container", {
      zoom: zoom,
      center:[108.839877,34.209659]
    });



    //设置当前真实位置
    function setCurrentLocation(lon, lat) {
        map.setZoomAndCenter(zoom, [lon, lat])
        var marker = new AMap.Marker({
        position: new AMap.LngLat(lon, lat),
            icon: 'https://a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png',
            anchor: 'bottom-center',
            map:map
        });
        map.add(marker);

        map.plugin(['AMap.PlaceSearch'], function() {
            var PlaceSearchOptions = { //设置PlaceSearch属性
                pageSize: 4, //每页结果数,默认4
                pageIndex: 1, //请求页码，默认1
                extensions: "base" //返回信息详略，默认为base（基本信息）
            };
            var MSearch = new AMap.PlaceSearch(PlaceSearchOptions); //构造PlaceSearch类
            AMap.Event.addListener(MSearch, "complete", (result) => {
                //result:附近的位置
                //alert(JSON.stringify(result.poiList.pois))需要传给鸿蒙
                window.swift.receiveHtmlData(JSON.stringify(result.poiList.pois))

            }); //返回结果
            MSearch.searchNearBy("华为西安研究所", [lon, lat]); //关键字查询
        });
    }

    window.onload = function() {
        setCurrentLocation(108.839877, 34.209659)
    }
</script>